package com.sci.web.controller;

import org.apache.log4j.Logger;

import com.alibaba.fastjson.JSONObject;
import com.jfinal.core.Controller;
import com.sci.config.MyConstants;
import com.sci.web.model.genmodel.User;
import com.sci.web.util.Result;

/**
 * Created by LiuFei.
 * Copyright (c) 2016, All Rights Reserved.
 * 
 */
public class BaseController extends Controller {

	private  Logger log=Logger.getLogger("LX-APP");
    

   /* public Integer defaultPageSize() {
        return StrUtil.str2int(MyConstants.getValue("pageSize"));
    }*/

    public void success() {
        success(null);
    }

    public void success(Object object) {
    	log.info("=====>BaseController-返回数据:"+JSONObject.toJSONString(object));
        renderJson(new Result(MyConstants.CODE_SUCCESS, MyConstants.DESC_SUCCESS, object));
    }

    public void error(String message) {

        renderJson(new Result(MyConstants.CODE_FAILURE, message, null));
    }
    public void error(Object object) {
        renderJson(new Result(MyConstants.CODE_FAILURE, MyConstants.DESC_FAILURE, object));
    }
    
    
    
    public User getSessionByUser(){
    	Object sessionAttr = getSessionAttr("user");
    	if(sessionAttr!=null){
    		return (User)sessionAttr;
    	}else{
    		return null;
    	}
    }
    
    
    
    
    
    

    public String getParameter(String name) {
    	String v = getRequest().getParameter(name);
    	if ("".equals(v) || null == v || v.equals("'")) {
    		return null;
    	} else {
    		return v;
    	}
	}
    
    public String getBasePara(String name) {
    	String v = getRequest().getParameter(name);
    	if ("".equals(v) || null == v || v.equals("'")) {
    		return null;
    	} else {
    		return v;
    	}
	}
    
    
    public int getBaseParToInt(String name) {
    	Integer paraToInt = getParaToInt(name);
    	if (paraToInt == null) {
    		return 0;
    	} else {
    		return paraToInt;
    	}
	}
    
}
